#include "xmlrpcparser.h"
#include "xmlrpcrequest.h"

#include <QtCore/QVariant>

namespace XmlRpc {

class XmlRpcRequestPrivate : public QSharedData {
public:
    inline XmlRpcRequestPrivate()
        : anonymousQuery(false), method("")
    {
    }

    inline XmlRpcRequestPrivate(const XmlRpcRequestPrivate &other)
        : QSharedData(other), anonymousQuery(other.anonymousQuery),
          method(other.method), params(other.params)
    {
    }

    bool anonymousQuery;
    QString method;
    QList<QVariant> params;
    XmlRpcRequest::Propagate propagate;
};

XmlRpcRequest::XmlRpcRequest(Propagate propagate)
    : d(new XmlRpcRequestPrivate)
{
    d->propagate = propagate;
}

XmlRpcRequest::XmlRpcRequest(const QString &method, Propagate propagate)
    : d(new XmlRpcRequestPrivate)
{
    d->propagate = propagate;
    d->method = method;
}

XmlRpcRequest::XmlRpcRequest(const QString &method, const QList<QVariant> &params,
                       Propagate propagate)
    : d(new XmlRpcRequestPrivate)
{
    d->propagate = propagate;
    d->method = method;
    d->params = params;
}

XmlRpcRequest::XmlRpcRequest(const XmlRpcRequest &other)
    : d(other.d)
{
}

XmlRpcRequest::~XmlRpcRequest()
{
    d = 0;
}

void XmlRpcRequest::setAnonymousQuery(bool value)
{
    d->anonymousQuery = value;
}

bool XmlRpcRequest::anonymousQuery() const
{
    return d->anonymousQuery;
}

void XmlRpcRequest::setMethod(const QString &method)
{
    d->method = method;
}

QString XmlRpcRequest::method() const
{
    return d->method;
}

XmlRpcRequest::Propagate XmlRpcRequest::propagate() const
{
    return d->propagate;
}

XmlRpcRequest::RpcMethodParamError XmlRpcRequest::setParams(const QList<QVariant> &params)
{
    d->params = params;
    return NoError;
}

QList<QVariant> XmlRpcRequest::params() const
{
    return d->params;
}

} // namespace XmlRpc
